﻿using System;
using SLNGP.Common.IoC;
using SLNGP.Core.Genes;
using SLNGP.Core.GeneticPrograms;

namespace SLNGP.Core.Individuals
{
    public class Chromosome : IChromosome
    {
        public Chromosome()
        {
        }

        private IGene _rootGene;
        public IGene RootGene
        {
            get { return _rootGene; }
            set
            {
                _rootGene = value;
                _rootGene.ParentChromosome = this;
            }
        }

        public bool IsValid
        {
            get { return RootGene.IsValid; }
        }

        public void Fix()
        {
            RootGene.Fix();
        }

        public IChromosome CloneChild(IIndividual parentIndividual)
        {
            var ReturnValue = IoC.Get<IChromosome>();
            ReturnValue.ParentIndividual = parentIndividual;
            ReturnValue.RootGene = RootGene.ChildClone(null, ReturnValue);
            return ReturnValue;
        }

        public IGeneticProgram ParentGeneticProgram
        {
            get
            {
                return ParentIndividual.ParentGeneticProgram;
            }
        }

        public IIndividual ParentIndividual { get; set; }

        public string GetStringDisplay()
        {
            return RootGene.GetStringDisplay();
        }

        public override string ToString()
        {
            return RootGene.ToString();
        }
    }
}